<template>
	<view class="page">
		<image src="https://hzybucket.obs.cn-south-1.myhuaweicloud.com/we_chat/top-bg.png" class="bg-color" mode="aspectFill"></image>
		<z-paging-swiper>
			<template #top>
				<uv-navbar bgColor="rgba(0,0,0,0)" @leftClick="leftClick" :fixed="false" title="增减项详情"></uv-navbar>

				<view class="tab-box">
					<view class="tab-box-content">
						<uv-tabs
							:list="data.tabList"
							:itemStyle="{ height: '100rpx' }"
							:inactiveStyle="{ color: '#828A9D', fontSize: '28rpx' }"
							:activeStyle="{ color: '#3B75FF', fontSize: '28rpx' }"
							lineColor="#3B75FF"
							@change="tabActiveFunc"
							:current="data.tabActive"
						></uv-tabs>
					</view>
				</view>
			</template>

			<swiper class="swiper" :current="data.tabActive" @animationfinish="swiperAnimationfinish">
				<!-- 操作历史 -->
				<swiper-item class="swiper-item">
					<z-paging ref="paging2" refresher-only @onRefresh="onRefresh('paging2')">
						<!-- 操作历史 -->
						<view class="project-box">
							<view class="uv-steps-box">
								<uv-steps direction="column">
									<uv-steps-item v-for="(item, index) in changeInfo.log_list" :key="index">
										<template v-slot:icon>
											<view class="uv-steps-box-tips"></view>
										</template>
										<template v-slot:desc>
											<view class="steps-box">
												<view class="steps-box-top">
													<view class="time">{{ item.created_at }}</view>
													<view class="user-data">
														<image class="user-avater" :src="item.handlers_image"></image>
														<view class="user-name">{{ item.handlers_position }}-{{ item.handlers_name }}</view>
													</view>
												</view>
												<view class="steps-box-data">
													<view class="steps-box-data-title">{{ item.content }}</view>
													<view class="table-content" v-if="item.change_status == 10 && item.handlers_position != '造价主管'">
														<view class="table-item w-50" v-if="fieldShowFunc('reason_type')">
															<view class="table-item-title">增减项原因</view>
															<view class="table-item-content">
																{{ changeInfo.reason_type == 1 ? '客户原因' : changeInfo.reason_type == 2 ? '现场原因' : '其他' }}
															</view>
														</view>
														<view class="table-item w-50" v-if="fieldShowFunc('increase_or_decrease')">
															<view class="table-item-title">增减项类型</view>
															<view class="table-item-content">
																{{ changeInfo.increase_or_decrease == 1 ? '增项' : '减项' }}
															</view>
														</view>
														<view class="table-item w-50" v-if="changeInfo.increase_or_decrease == 1">
															<view class="table-item-title">预计开工日期</view>
															<view class="table-item-content size-11">{{ changeInfo.start_date }}</view>
														</view>
														<view class="table-item w-50" v-if="changeInfo.increase_or_decrease == 1">
															<view class="table-item-title">预计完工日期</view>
															<view class="table-item-content size-11">{{ changeInfo.end_date }}</view>
														</view>
														<view class="table-item w-50" v-if="changeInfo.increase_or_decrease == 1">
															<view class="table-item-title">预计工期</view>
															<view class="table-item-content">{{ changeInfo.expect_duration_days }}天</view>
														</view>
														<view class="table-item w-50" v-if="fieldShowFunc('change_content')">
															<view class="table-item-title">增减项内容</view>
															<view class="table-item-content">
																{{ changeContent(changeInfo.change_content) }}
															</view>
														</view>
														<view class="table-item" v-if="fieldShowFunc('construction_content')">
															<view class="table-item-title">施工内容</view>
															<view class="table-item-content">
																{{ changeInfo.construction_content }}
															</view>
														</view>
														<view class="table-item">
															<view class="table-item-title">备注</view>
															<view class="table-item-content">{{ changeInfo.remark || '--' }}</view>
														</view>
														<view class="table-item" v-if="fieldShowFunc('change_items_file')">
															<view class="table-item-title">附件</view>
															<view class="table-item-content">
																<view
																	@click="preFileFunc(item2)"
																	class="table-item-file-name"
																	v-for="(item2, idx) in changeInfo.change_items_file"
																	:key="idx"
																>
																	{{ item2.file_name }}
																</view>
																<view v-if="changeInfo.change_items_file.length == 0">--</view>
															</view>
														</view>
													</view>

													<view class="table-content" v-if="item.change_status == 20">
														<view class="table-item w-50" v-if="fieldShowFunc('change_items_file')">
															<view class="table-item-title">报价类型</view>
															<view class="table-item-content">
																{{
																	item.form_data.quotation_type == 1
																		? '基础施工报价(首次)'
																		: item.form_data.quotation_type == 2
																		? '基础施工报价(调整)'
																		: '增减项施工报价'
																}}
															</view>
														</view>
														<view class="table-item w-50" v-if="fieldShowFunc('quotation_amount')">
															<view class="table-item-title">报价金额</view>
															<view class="table-item-content">{{ item.form_data.quotation_amount }}元</view>
														</view>
														<view class="table-item w-50" v-if="fieldShowFunc('basic_decoration_fee')">
															<view class="table-item-title">基础装修费</view>
															<view class="table-item-content">{{ item.form_data.basic_decoration_fee }}元</view>
														</view>
														<view class="table-item w-50" v-if="fieldShowFunc('material_costs')">
															<view class="table-item-title">主材采购费</view>
															<view class="table-item-content">{{ item.form_data.material_costs }}元</view>
														</view>
														<view class="table-item w-50" v-if="fieldShowFunc('quotation_taxes')">
															<view class="table-item-title">税金</view>
															<view class="table-item-content">{{ item.form_data.quotation_taxes }}元</view>
														</view>
														<view class="table-item w-50" v-if="fieldShowFunc('cost_amount')">
															<view class="table-item-title">成本金额</view>
															<view class="table-item-content">{{ item.form_data.cost_amount }}元</view>
														</view>
														<view class="table-item w-50" v-if="fieldShowFunc('procurement_cost')">
															<view class="table-item-title">现场采购成本</view>
															<view class="table-item-content">{{ item.form_data.procurement_cost }}元</view>
														</view>
														<view class="table-item w-50" v-if="fieldShowFunc('centralized_procurement_cost')">
															<view class="table-item-title">公司集采成本</view>
															<view class="table-item-content">{{ item.form_data.centralized_procurement_cost }}元</view>
														</view>
														<view class="table-item w-50" v-if="fieldShowFunc('management_costs')">
															<view class="table-item-title">管理成本</view>
															<view class="table-item-content">{{ item.form_data.management_costs }}元</view>
														</view>
														<view class="table-item w-50" v-if="fieldShowFunc('profit_amount')">
															<view class="table-item-title">利润金额</view>
															<view class="table-item-content">{{ item.form_data.profit_amount }}元</view>
														</view>
														<view class="table-item w-50" v-if="fieldShowFunc('profit_ratio')">
															<view class="table-item-title">利润率</view>
															<view class="table-item-content">{{ item.form_data.profit_ratio }}%</view>
														</view>
														<view class="table-item w-50" v-if="fieldShowFunc('change_amount')">
															<view class="table-item-title">增减项金额</view>
															<view class="table-item-content">{{ item.form_data.change_amount }}元</view>
														</view>
														<view class="table-item" v-if="fieldShowFunc('quotation_file')">
															<view class="table-item-title">报价附件</view>
															<view class="table-item-content">
																<template v-for="(item2, idx) in item.form_data.project_quotation_file" :key="idx">
																	<view @click="preFileFunc(item2)" class="table-item-file-name" v-if="item2.type == 1">
																		{{ item2.file_name }}
																	</view>
																</template>
															</view>
														</view>
														<view class="table-item" v-if="fieldShowFunc('cost_list_file')">
															<view class="table-item-title">成本附件</view>
															<view class="table-item-content">
																<template v-for="(item2, idx) in item.form_data.project_quotation_file" :key="idx">
																	<view @click="preFileFunc(item2)" class="table-item-file-name" v-if="item2.type == 2">
																		{{ item2.file_name }}
																	</view>
																</template>
															</view>
														</view>
														<view class="table-item" v-if="fieldShowFunc('profit_statement_file')">
															<view class="table-item-title">利润附件</view>
															<view class="table-item-content">
																<template v-for="(item2, idx) in item.form_data.project_quotation_file" :key="idx">
																	<view @click="preFileFunc(item2)" class="table-item-file-name" v-if="item2.type == 3">
																		{{ item2.file_name }}
																	</view>
																</template>
															</view>
														</view>
													</view>

													<view class="table-content" v-if="item.change_status == 25">
														<view class="table-item">
															<view class="table-item-title">拒绝理由</view>
															<view class="table-item-content">{{ item.remark }}</view>
														</view>
													</view>

													<view class="table-content" v-if="item.change_status == 35">
														<view class="table-item">
															<view class="table-item-title">拒绝理由</view>
															<view class="table-item-content">{{ item.remark }}</view>
														</view>
													</view>

													<view class="table-content" v-if="item.change_status == 50">
														<view class="table-item w-50" v-if="fieldShowFunc('payment_type')">
															<view class="table-item-title">收款类型</view>
															<view class="table-item-content">增项款</view>
														</view>
														<view class="table-item w-50" v-if="fieldShowFunc('amount_collected')">
															<view class="table-item-title">收款金额</view>
															<view class="table-item-content">{{ item.form_data.amount_collected }}元</view>
														</view>
														<view class="table-item" v-if="fieldShowFunc('receiving_account') || fieldShowFunc('account_number')">
															<view class="table-item-title">收款账户</view>
															<view class="table-item-content">
																{{ fieldShowFunc('receiving_account') ? item.form_data.receiving_account : '' }}
																{{ fieldShowFunc('account_number') ? item.form_data.account_number : '' }}
															</view>
														</view>
														<view class="table-item dh" v-if="fieldShowFunc('voucher_file')">
															<view class="table-item-title">收款凭证</view>
															<view class="steps-box-data-list">
																<image
																	@click="preFileFunc(item2)"
																	v-for="(item2, idx) in item.form_data.voucher_file"
																	:key="idx"
																	class="steps-box-data-list-image"
																	:src="item2.file_url"
																></image>
															</view>
														</view>
														<!-- <view class="table-item" v-else>
															<view class="table-item-title">收款金额</view>
															<view class="table-item-content">无权限</view>
														</view> -->
													</view>

													<view class="table-content" v-if="item.change_status == 55">
														<view class="table-item">
															<view class="table-item-title">驳回理由</view>
															<view class="table-item-content">{{ item.remark }}</view>
														</view>
													</view>
												</view>
											</view>
										</template>
									</uv-steps-item>
								</uv-steps>
							</view>
						</view>
					</z-paging>
				</swiper-item>
				<!-- 详细信息 -->
				<swiper-item class="swiper-item">
					<z-paging ref="paging1" refresher-only @onRefresh="onRefresh('paging1')">
						<view class="ios">
							<view class="content-box">
								<view class="content-box-item">
									<view class="title">项目名称</view>
									<view class="desc">{{ changeInfo.project_name }}</view>
								</view>
								<view class="content-box-item">
									<view class="title">项目编号</view>
									<view class="desc">{{ changeInfo.project_number }}</view>
								</view>
								<view class="content-box-item">
									<view class="title">发起人</view>
									<view class="desc">{{ changeInfo.user_name }}</view>
								</view>
								<view class="content-box-item" v-if="fieldShowFunc('increase_or_decrease')">
									<view class="title">增减类型</view>
									<view class="desc">{{ changeInfo.increase_or_decrease == 1 ? '增项' : '减项' }}</view>
								</view>
								<view class="content-box-item" v-if="changeInfo.increase_or_decrease == 1">
									<view class="title">预计开工日期</view>
									<view class="desc">{{ changeInfo.start_date }}</view>
								</view>
								<view class="content-box-item" v-if="changeInfo.increase_or_decrease == 1">
									<view class="title">预计完工日期</view>
									<view class="desc">{{ changeInfo.end_date }}</view>
								</view>
								<view class="content-box-item" v-if="changeInfo.increase_or_decrease == 1">
									<view class="title">预计工期</view>
									<view class="desc">{{ changeInfo.expect_duration_days }}天</view>
								</view>
								<view class="content-box-item" v-if="fieldShowFunc('reason_type')">
									<view class="title">增减项原因</view>
									<view class="desc">
										{{ changeInfo.reason_type == 1 ? '客户原因' : changeInfo.reason_type == 2 ? '现场原因' : '其他' }}
									</view>
								</view>
								<view class="content-box-item" v-if="fieldShowFunc('change_content')">
									<view class="title">增减内容</view>
									<view class="desc">{{ changeContent(changeInfo.change_content) }}</view>
								</view>
								<view class="content-box-item" v-if="fieldShowFunc('construction_content')">
									<view class="title">施工内容说明</view>
									<view class="desc">{{ changeInfo.construction_content }}</view>
								</view>
								<view class="content-box-item" v-if="fieldShowFunc('change_items_file')">
									<view class="title">附件</view>
									<view class="desc">
										<view @click="preFileFunc(item)" class="file-item underline" v-for="(item, idx) in changeInfo.change_items_file" :key="idx">
											{{ item.file_name }}
										</view>
										<span v-if="changeInfo.change_items_file && changeInfo.change_items_file.length == 0">--</span>
									</view>
								</view>
								<view class="content-box-item">
									<view class="title">备注</view>
									<view class="desc">{{ changeInfo.remark ? changeInfo.remark : '--' }}</view>
								</view>
							</view>
							<view class="tips" v-if="data.newBj">
								<view class="icon"></view>
								<view class="title">最新报价内容</view>
							</view>
							<view class="content-box" v-if="data.newBj">
								<view class="content-box-item" v-if="fieldShowFunc('quotation_type')">
									<view class="title">报价类型</view>
									<view class="desc">
										{{ data.newBj.quotation_type == 1 ? '基础施工报价(首次)' : data.newBj.quotation_type == 2 ? '基础施工报价(调整)' : '增减项施工报价' }}
									</view>
								</view>
								<view class="content-box-item" v-if="fieldShowFunc('quotation_amount')">
									<view class="title">报价金额</view>
									<view class="desc">{{ data.newBj.quotation_amount }}元</view>
								</view>
								<view class="content-box-item" v-if="fieldShowFunc('basic_decoration_fee')">
									<view class="title">基础装修费</view>
									<view class="desc">{{ data.newBj.basic_decoration_fee }}元</view>
								</view>
								<view class="content-box-item" v-if="fieldShowFunc('material_costs')">
									<view class="title">主材采购费</view>
									<view class="desc">{{ data.newBj.material_costs }}元</view>
								</view>
								<view class="content-box-item" v-if="fieldShowFunc('quotation_taxes')">
									<view class="title">税金</view>
									<view class="desc">{{ data.newBj.quotation_taxes }}元</view>
								</view>
								<view class="content-box-item" v-if="fieldShowFunc('cost_amount')">
									<view class="title">成本金额</view>
									<view class="desc">{{ data.newBj.cost_amount }}元</view>
								</view>
								<view class="content-box-item" v-if="fieldShowFunc('procurement_cost')">
									<view class="title">现场采购成本</view>
									<view class="desc">{{ data.newBj.procurement_cost }}元</view>
								</view>
								<view class="content-box-item" v-if="fieldShowFunc('centralized_procurement_cost')">
									<view class="title">公司集采成本</view>
									<view class="desc">{{ data.newBj.centralized_procurement_cost }}元</view>
								</view>
								<view class="content-box-item" v-if="fieldShowFunc('management_costs')">
									<view class="title">管理成本</view>
									<view class="desc">{{ data.newBj.management_costs }}元</view>
								</view>
								<view class="content-box-item" v-if="fieldShowFunc('profit_amount')">
									<view class="title">利润金额</view>
									<view class="desc">{{ data.newBj.profit_amount }}元</view>
								</view>
								<view class="content-box-item" v-if="fieldShowFunc('profit_ratio')">
									<view class="title">利润率</view>
									<view class="desc">{{ data.newBj.profit_ratio }}%</view>
								</view>
								<view class="content-box-item" v-if="fieldShowFunc('change_amount')">
									<view class="title">增减项金额</view>
									<view class="desc">{{ data.newBj.change_amount }}元</view>
								</view>
								<view class="content-box-item" v-if="fieldShowFunc('quotation_file')">
									<view class="title">报价附件</view>
									<view class="desc">
										<template v-for="(item, idx) in data.newBj.project_quotation_file" :key="idx">
											<view @click="preFileFunc(item)" class="file-item underline" v-if="item.type == 1">{{ item.file_name }}</view>
										</template>
									</view>
								</view>
								<view class="content-box-item" v-if="fieldShowFunc('cost_list_file')">
									<view class="title">成本附件</view>
									<view class="desc">
										<template v-for="(item, idx) in data.newBj.project_quotation_file" :key="idx">
											<view @click="preFileFunc(item)" class="file-item underline" v-if="item.type == 2">{{ item.file_name }}</view>
										</template>
									</view>
								</view>
								<view class="content-box-item" v-if="fieldShowFunc('profit_statement_file')">
									<view class="title">利润附件</view>
									<view class="desc">
										<template v-for="(item, idx) in data.newBj.project_quotation_file" :key="idx">
											<view @click="preFileFunc(item)" class="file-item underline" v-if="item.type == 3">{{ item.file_name }}</view>
										</template>
									</view>
								</view>
							</view>
						</view>
					</z-paging>
				</swiper-item>
			</swiper>

			<!-- 操作区 -->
			<template #bottom>
				<view class="bottom-box ios" v-if="data.userInfo.position_id == 4 && changeInfo.change_status == 10">
					<uv-button type="primary" text="重新分配造价员" customStyle="width: 100%;" @click="$refs.zjyPicker.open()"></uv-button>
				</view>
				<view class="bottom-box ios" v-if="data.userInfo.position_id == 7 && changeInfo.change_status == 20">
					<uv-button type="primary" text="造价单审核" customStyle="width: 100%;" @click="$refs.zjdsh.open('bottom')"></uv-button>
				</view>
				<view class="bottom-box ios" v-if="data.userInfo.position_id == 4 && changeInfo.change_status == 30">
					<uv-button type="primary" text="造价单审核" customStyle="width: 100%;" @click="$refs.zjdsh.open('bottom')"></uv-button>
				</view>
				<view class="bottom-box ios" v-if="data.userInfo.position_id == 2 && changeInfo.change_status == 40">
					<uv-button type="primary" text="提交增项收款凭证" customStyle="width: 100%;" @click="openPopup"></uv-button>
				</view>
				<view class="bottom-box ios" v-if="data.userInfo.position_id == 9 && changeInfo.change_status == 50">
					<uv-button type="primary" text="收款确认" customStyle="width: 100%;" @click="$refs.skqr.open('bottom')"></uv-button>
				</view>
			</template>
		</z-paging-swiper>

		<!-- 分配造价员 -->
		<uv-picker title="分配造价员" ref="zjyPicker" :columns="data.zjyColumns" @confirm="cxfpzjySubmit" keyName="name"></uv-picker>

		<!-- 造价单审核 -->
		<uv-popup ref="zjdsh" mode="bottom" :round="10" @maskClick="closeFunc('zjdsh')">
			<view class="popup-box">
				<view class="title">造价单审核</view>
				<scroll-view class="scroll-view" scroll-y>
					<view class="uv-form-box">
						<uv-form labelPosition="top" :model="data.zjdshForm" :rules="data.zjdshRules" ref="zjdshForm" labelWidth="auto">
							<uv-form-item label="" prop="reviewPassed">
								<uv-radio-group v-model="data.zjdshForm.reviewPassed">
									<uv-radio :customStyle="{ margin: '8px' }" label="通过" :name="1"></uv-radio>
									<uv-radio :customStyle="{ margin: '8px' }" label="拒绝" :name="2"></uv-radio>
								</uv-radio-group>
							</uv-form-item>

							<uv-form-item label="备注" prop="remark">
								<uv-textarea height="100" v-model="data.zjdshForm.remark" placeholder="请输入备注"></uv-textarea>
							</uv-form-item>
						</uv-form>
					</view>
				</scroll-view>
				<view class="btn-box">
					<uv-button @click="closeFunc('zjdsh')" text="取 消" customStyle="width: 180rpx;"></uv-button>
					<uv-button @click="shbjdSubmit('zjdsh')" type="primary" text="提 交" customStyle="width: 500rpx;"></uv-button>
				</view>
			</view>
		</uv-popup>

		<!-- 提交收款凭证 -->
		<uv-popup ref="sfpz" mode="bottom" :round="10" @maskClick="closeFunc('sfpz')">
			<view class="popup-box">
				<view class="title">提交增项收款凭证</view>
				<scroll-view class="scroll-view" scroll-y>
					<view class="uv-form-box">
						<uv-form labelPosition="top" :model="data.sfpzForm" :rules="data.sfpzRules" ref="sfpzForm" labelWidth="auto">
							<uv-form-item label="收款金额" prop="amount_collected" required>
								<uv-input type="digit" placeholder="请输入收款金额" v-model="data.sfpzForm.amount_collected"></uv-input>
							</uv-form-item>
							<uv-form-item label="收款账户" prop="zhType.name" @click="$refs.zhPicker.open()" required>
								<!--  border="bottom" -->
								<uv-input readonly placeholder="请选择收款账户" v-model="data.sfpzForm.zhType.name" suffixIcon="arrow-right"></uv-input>
							</uv-form-item>
							<uv-form-item label="凭证文件" prop="payment_voucher" labelPosition="left" required>
								<view class="file-box">
									<uv-button
										type="info"
										text="点击上传"
										@click="uploadFunc"
										icon="plus"
										iconSize="24rpx"
										iconColor="#8F8F8F"
										customTextStyle="font-size: 24rpx;color: #8F8F8F;"
										customStyle="width: 170rpx;height: 60rpx;border-radius: 8rpx;"
									></uv-button>
								</view>
							</uv-form-item>
							<view class="file-list">
								<view class="file-media" v-for="(item, index) in data.sfpzForm.payment_voucher" :key="index">
									<view class="del-icon" @click.stop="delFile(index)">
										<uv-icon name="trash" size="15" color="#ffffff"></uv-icon>
									</view>
									<image mode="aspectFill" :src="item.tempFilePath" class="media-item"></image>
								</view>
							</view>
							<uv-form-item label="备注" prop="remark">
								<uv-textarea height="100" v-model="data.sfpzForm.remark" placeholder="请输入内容"></uv-textarea>
							</uv-form-item>
						</uv-form>
					</view>
				</scroll-view>
				<view class="btn-box">
					<uv-button @click="closeFunc('sfpz')" text="取 消" customStyle="width: 180rpx;"></uv-button>
					<uv-button @click="sfpzSubmit('sfpz')" type="primary" text="提 交" customStyle="width: 500rpx;"></uv-button>
				</view>
			</view>
		</uv-popup>
		<!-- 账户列表 -->
		<uv-picker title="账户列表" ref="zhPicker" :columns="data.zhColumns" @confirm="pickerConfirm($event, 'zhType')" keyName="name"></uv-picker>

		<!-- 收款确认 -->
		<uv-popup ref="skqr" mode="bottom" :round="10" @maskClick="closeFunc('skqr')">
			<view class="popup-box">
				<view class="title">收款确认</view>
				<scroll-view class="scroll-view" scroll-y>
					<view class="uv-form-box">
						<uv-form labelPosition="top" :model="data.skqrForm" :rules="data.skqrRules" ref="skqrForm" labelWidth="auto">
							<uv-form-item label="" prop="reviewPassed">
								<uv-radio-group v-model="data.skqrForm.reviewPassed">
									<uv-radio :customStyle="{ margin: '8px' }" label="通过" :name="1"></uv-radio>
									<uv-radio :customStyle="{ margin: '8px' }" label="驳回" :name="2"></uv-radio>
								</uv-radio-group>
							</uv-form-item>

							<uv-form-item label="备注" prop="remark">
								<uv-textarea height="100" v-model="data.skqrForm.remark" placeholder="请输入备注"></uv-textarea>
							</uv-form-item>
						</uv-form>
					</view>
				</scroll-view>
				<view class="btn-box">
					<uv-button @click="closeFunc('skqr')" text="取 消" customStyle="width: 180rpx;"></uv-button>
					<uv-button @click="skqrSubmit('skqr')" type="primary" text="提 交" customStyle="width: 500rpx;"></uv-button>
				</view>
			</view>
		</uv-popup>

		<!-- 文件预览 -->
		<preFileCom :fileObj="fileObj" @onFileSuccess="onFileSuccess"></preFileCom>
	</view>
</template>

<script setup>
import { ref, reactive, computed, getCurrentInstance } from 'vue';
import { onLoad } from '@dcloudio/uni-app';
const { proxy: that } = getCurrentInstance();

const changeInfo = ref('');
const data = reactive({
	id: '',
	userInfo: '',
	newBj: '',
	tabActive: 0,
	tabList: [
		{
			name: '操作历史'
		},
		{
			name: '详细信息'
		}
	],
	// 重新分配造价员
	zjyColumns: [],
	// 造价单审核
	zjdshForm: {
		reviewPassed: '',
		remark: ''
	},
	zjdshRules: {
		reviewPassed: {
			validator: (rule, value, callback) => {
				if (value) {
					return true;
				} else {
					return false;
				}
			},
			required: true,
			message: '请选择是否通过',
			trigger: ['change']
		},
		remark: {
			validator: (rule, value, callback) => {
				if (data.zjdshForm.reviewPassed == 1) {
					return true;
				} else {
					if (value) {
						return true;
					} else {
						return false;
					}
				}
			},
			required: true,
			message: '请输入拒绝理由',
			trigger: ['change']
		}
	},

	// 收款凭证
	sfpzForm: {
		amount_collected: '',
		zhType: '',
		remark: '',
		payment_voucher: []
	},
	sfpzRules: {
		amount_collected: { required: true, message: '请输入收款金额', trigger: 'change' },
		'zhType.name': { required: true, message: '请选择收款账户', trigger: 'change' },
		payment_voucher: {
			validator: (rule, value, callback) => {
				if (value.length > 0) {
					return true;
				} else {
					return false;
				}
			},
			required: true,
			message: '请上传支付凭证',
			trigger: 'change'
		}
	},
	zhColumns: [],

	// 收款确认
	skqrForm: {
		reviewPassed: '',
		remark: ''
	},
	skqrRules: {
		reviewPassed: {
			validator: (rule, value, callback) => {
				if (value) {
					return true;
				} else {
					return false;
				}
			},
			required: true,
			message: '请选择是否通过',
			trigger: ['change']
		},
		remark: {
			validator: (rule, value, callback) => {
				if (data.skqrForm.reviewPassed == 1) {
					return true;
				} else {
					if (value) {
						return true;
					} else {
						return false;
					}
				}
			},
			required: true,
			message: '请输入拒绝理由',
			trigger: ['change']
		}
	},

	preVideoShow: false,
	currVideo: '',

	fieldList: []
});

onLoad((e) => {
	data.id = e.id;
	data.userInfo = uni.getStorageSync('userInfo');
	getChangeDetails();
	getOrganizationDetails();
});
const changeContent = computed(() => (type) => {
	let res = '';
	switch (type) {
		case 1:
			res = '顶面工程';
			break;
		case 2:
			res = '地面工程';
			break;
		case 3:
			res = '墙面工程';
			break;
		case 4:
			res = '水电工程';
			break;
		case 5:
			res = '楼梯工程';
			break;
		case 6:
			res = '广告工程';
			break;
		case 7:
			res = '外立面工程';
			break;
		case 8:
			res = '其他工程';
			break;
	}
	return res;
});

const onRefresh = (name) => {
	getChangeDetails(name);
};
const tabActiveFunc = (e) => {
	data.tabActive = e.index;
};

const swiperAnimationfinish = (e) => {
	console.log(e, 'swiperAnimationfinish');
	data.tabActive = e.detail.current;
};

const getChangeDetails = (name) => {
	that.$hApi
		.getChangeDetails({
			change_id: data.id
		})
		.then((res) => {
			console.log(res, 'getChangeDetails');
			if (res.code == 200) {
				changeInfo.value = res.data;
				let arr = [];
				res.data.log_list.map((item) => {
					if (item.change_status == 20) {
						arr.push(item);
					}
				});
				data.newBj = arr.length > 0 ? arr[0].form_data : '';

				// 获取造价员列表
				console.log(data.userInfo.position_id, res.data.change_status);
				if (data.userInfo.position_id == 4 && res.data.change_status == 10) {
					getAdminList();
				}
			}
			if (name) {
				that.$refs[name].complete();
			}
		});
};
// 重新分配造价员
const getAdminList = () => {
	that.$Api
		.wxGetAdminList({
			page: 1,
			num: 99,
			identity: 1,
			position_id_arr: [5]
		})
		.then((res) => {
			console.log(res, 'getAdminList');
			if (res.code == 200) {
				data.zjyColumns = [res.data.list];
			}
		});
};
const cxfpzjySubmit = (e) => {
	uni.showLoading({
		mask: true,
		title: '信息提交中...'
	});
	that.$hApi
		.changeItemsAssignCostEstimator({
			project_id: changeInfo.value.project_id,
			change_id: data.id,
			cost_estimator_id: e.value[0].id
		})
		.then((res) => {
			uni.hideLoading();
			if (res.code == 200) {
				getChangeDetails();
			}
			uni.showToast({
				title: res.code == 200 ? '操作成功' : res.message,
				icon: res.code == 200 ? 'success' : 'error'
			});
		})
		.catch((err) => {
			uni.hideLoading();
		});
};
// 造价单审核
const closeFunc = (name) => {
	that.$refs[`${name}Form`].resetFields();
	that.$refs[`${name}Form`].clearValidate();
	that.$refs[name].close();
};
const shbjdSubmit = (formName) => {
	console.log(data.zjdshForm, changeInfo.value);
	that.$refs[`${formName}Form`]
		.validate()
		.then((res) => {
			let zjdshForm = data.zjdshForm;
			uni.showLoading({
				mask: true,
				title: '信息提交中...'
			});
			if (zjdshForm.reviewPassed == 1) {
				that.$hApi
					.changeQuotationPassed({
						project_id: changeInfo.value.project_id,
						change_id: data.id,
						remark: zjdshForm.remark
					})
					.then((res) => {
						console.log(res, '通过');
						uni.hideLoading();
						if (res.code == 200) {
							closeFunc(formName);
							getChangeDetails();
						}
						uni.showToast({
							title: res.code == 200 ? '操作成功' : res.message,
							icon: res.code == 200 ? 'success' : 'error'
						});
					})
					.catch((err) => {
						uni.hideLoading();
					});
			} else {
				that.$hApi
					.changeQuotationRejected({
						project_id: changeInfo.value.project_id,
						change_id: data.id,
						remark: zjdshForm.remark
					})
					.then((res) => {
						console.log(res, '拒绝');
						uni.hideLoading();
						if (res.code == 200) {
							closeFunc(formName);
							getChangeDetails();
						}
						uni.showToast({
							title: res.code == 200 ? '操作成功' : res.message,
							icon: res.code == 200 ? 'success' : 'error'
						});
					})
					.catch((err) => {
						uni.hideLoading();
					});
			}
		})
		.catch((errors) => {});
};

// 收款凭证
const openPopup = () => {
	that.$Api
		.getCompanyList({
			page: 1,
			num: 9999,
			account_type: 1
		})
		.then((res) => {
			console.log(res, '账户列表');
			if (res.code == 200) {
				res.data.list.map((item) => {
					item.name = item.account_name;
				});
				data.zhColumns = [res.data.list];
				console.log(data.zhColumns);
			}

			that.$refs.sfpz.open();
		});
};
const pickerConfirm = (e, type) => {
	data.sfpzForm[type] = e.value[0];
	that.$refs.sfpzForm.validateField(`${type}.name`);
};
const uploadFunc = () => {
	uni.chooseMedia({
		mediaType: ['image'],
		sourceType: ['album', 'camera'],
		success(res) {
			console.log(res.tempFiles);
			res.tempFiles.map((item) => {
				data.sfpzForm.payment_voucher.push(item);
			});
			that.$refs.sfpzForm.validateField('payment_voucher');
		}
	});
};
const delFile = (idx) => {
	data.sfpzForm.payment_voucher.splice(idx, 1);
};
const sfpzSubmit = (formName) => {
	that.$refs[`${formName}Form`]
		.validate()
		.then((res) => {
			let sfpzForm = data.sfpzForm;
			console.log(sfpzForm);
			uni.showLoading({
				mask: true,
				title: '信息提交中...'
			});
			that.$upload(sfpzForm.payment_voucher)
				.then((res) => {
					console.log(1111, res);
					that.$hApi
						.wxSubmitChangeVouchers({
							project_id: changeInfo.value.project_id,
							change_id: data.id,
							amount_collected: sfpzForm.amount_collected,
							receiving_account_id: sfpzForm.zhType.id,
							remark: sfpzForm.remark,
							payment_voucher: res.arrResult
						})
						.then((res) => {
							console.log(res, '收费凭证');
							uni.hideLoading();
							if (res.code == 200) {
								closeFunc(formName);
								getChangeDetails();
							}
							uni.showToast({
								title: res.code == 200 ? '操作成功' : res.message,
								icon: res.code == 200 ? 'success' : 'error'
							});
						})
						.catch((err) => {
							uni.hideLoading();
						});
				})
				.catch((err) => {
					uni.hideLoading();
				});
		})
		.catch((errors) => {});
};

// 收款确认
const skqrSubmit = (formName) => {
	console.log(data.zjdshForm, changeInfo.value);
	that.$refs[`${formName}Form`]
		.validate()
		.then((res) => {
			let skqrForm = data.skqrForm;
			uni.showLoading({
				mask: true,
				title: '信息提交中...'
			});
			if (skqrForm.reviewPassed == 1) {
				that.$hApi
					.confirmChangeVouchers({
						project_id: changeInfo.value.project_id,
						change_id: data.id,
						remark: skqrForm.remark
					})
					.then((res) => {
						console.log(res, '通过');
						uni.hideLoading();
						if (res.code == 200) {
							closeFunc(formName);
							getChangeDetails();
						}
						uni.showToast({
							title: res.code == 200 ? '操作成功' : res.message,
							icon: res.code == 200 ? 'success' : 'error'
						});
					})
					.catch((err) => {
						uni.hideLoading();
					});
			} else {
				that.$hApi
					.refuseChangeVouchers({
						project_id: changeInfo.value.project_id,
						change_id: data.id,
						remark: skqrForm.remark
					})
					.then((res) => {
						console.log(res, '拒绝');
						uni.hideLoading();
						if (res.code == 200) {
							closeFunc(formName);
							getChangeDetails();
						}
						uni.showToast({
							title: res.code == 200 ? '操作成功' : res.message,
							icon: res.code == 200 ? 'success' : 'error'
						});
					})
					.catch((err) => {
						uni.hideLoading();
					});
			}
		})
		.catch((errors) => {});
};

let fileObj = ref('');
const preFileFunc = (file) => {
	console.log(file);
	fileObj.value = file;
};
const onFileSuccess = () => {
	fileObj.value = '';
};

const getOrganizationDetails = () => {
	that.$Api
		.getOrganizationDetails({
			id: data.userInfo.position_id
		})
		.then((res) => {
			console.log(res, 'asdasdasd');
			if (res.code == 200) {
				let obj = {};
				let field_permissions = JSON.parse(res.data[0].field_permissions);
				obj = { ...field_permissions[3].field_list, ...field_permissions[6].field_list };
				data.fieldList = obj;
			}
		});
};

// 判断是否显示
const fieldShowFunc = (field) => {
	let fieldList = data.fieldList;
	return fieldList[field] == undefined ? true : fieldList[field];
};
const leftClick = () => {
	// 获取当前页面栈数组
	const pages = getCurrentPages();
	// 获取栈顶页面的实例
	const prevPage = pages[pages.length - 2]; //上一页
	if (!prevPage) {
		uni.reLaunch({
			url: '/pages/index/index'
		});
	} else {
		uni.navigateBack();
	}
	console.log('返回上一页', prevPage);
};
</script>

<style lang="scss" scoped>
@import './index.scss';
</style>
